﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;

namespace PCCardN.Pages
{
    public partial class Frm_Search : Form
    {
        DataTable dt = new DataTable();
        SqlHelper SqlHelper = new SqlHelper();
       
        public Frm_Search()
        {
            InitializeComponent();
        }

        private void 一键查询_Click(object sender, EventArgs e)
        {
            if (this.txtSearch.ControlText.Equals(""))
            {
                return;
            }
            string CommandText = "select UserName,C_ID,Photo,UserCertifyCardNo,CardUnit,CardDepart,CardType from Card_Table where UserName like '%" + this.txtSearch.ControlText + "%'"
                                    + " or  CardGroup like '%" + this.txtSearch.ControlText + "%'"
                                     + " or  CardNO like '%" + this.txtSearch.ControlText + "%'"
                                      + " or  CardUnit like '%" + this.txtSearch.ControlText + "%'"
                                       + " or  C_ID like '" + this.txtSearch.ControlText + "'";
            DataTable dt = SqlHelper.GetQueryResult(CommandText);
            this.dataGridViewX1.DataSource = dt;
            
            
        }
        //private void BindData(DataTable dt)
        //{
        //    this.imageList1.Images.Clear();
        //    for(int i = 0; i < dt.Rows.Count; i++)
        //    {
        //        imageList1.Images.Add()
        //    }
        //    this.lsvInfo.Items.Clear();
        //    for (int i = 0; i < dt.Rows.Count; i++)
        //    {
        //        ListViewItem lvi = new ListViewItem(dt.Rows[i]["CardID"].ToString());  //ListView的第一个Item作为主项需要单独添加  
                
        //        lvi.SubItems.Add(dt.Rows[i]["UserName"].ToString());   //后面添加的Item都为SubItems ，即为子项  
        //        lvi.SubItems.Add(dt.Rows[i]["CardUnit"].ToString());
        //        lvi.SubItems.Add((byte[])dt.Rows[i]["Photo"].ToString());
        //        lvi.SubItems.Add(dt.Rows[i]["CardType"].ToString());
        //        lvi.SubItems.Add(dt.Rows[i]["CardDepart"].ToString());
               
        //        this.lsvInfo.Items.Add(lvi);//最后进行添加  
        //        Button button = new Button();
        //        Button btn2 = new Button();
        //        btn2.Text = "查看";
        //       btn2.Click += new System.EventHandler(btn_clickRefuse);
        //        btn2.Show();
        //        this.lsvInfo.Controls.Add(btn2);
        //    }
        //}

      

        private void dataGridViewX1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex != 0)
            {
                return;
            }

            FrmDetail frm = new FrmDetail();
            frm.Id = this.dataGridViewX1.Rows[e.RowIndex].Cells[2].Value.ToString();
            frm.ShowDialog();
        }

        private void dataGridViewX1_DoubleClick(object sender, EventArgs e)
        {
            int RowIndex = this.dataGridViewX1.CurrentRow.Index;
            FrmDetail frm = new FrmDetail();
            frm.Id = this.dataGridViewX1.Rows[RowIndex].Cells[2].Value.ToString();
            frm.ShowDialog();
        }
    }
}
